<%-- 
    Document   : muestra_consultas
    Created on : 18/11/2009, 08:35:00 PM
    Author     : Eduardo
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="Model.JConexion" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.Iterator" %>
<%@page import="javax.servlet.http.HttpServlet" %>
<%@page import="javax.servlet.http.HttpServletRequest" %>
<%@page import="javax.servlet.http.HttpServletResponse" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Muestra Datos</title>
    </head>
    <body>
        <form action="muestra_consultas.jsp" method="post">
            
                <%
                HttpSession sesion = null;
                String consulta = "";
                int idcarrera = 0;
                String query = "";
                String user = "";                
                if(!(user.equals(null))){
                    user = request.getParameter("user");                    
                }else{
                    response.sendRedirect("login.jsp");
                }
                String[] dat;
                //consulta = sesion.getAttribute("cosulta").toString();
                consulta = request.getParameter("consulta");
                idcarrera = Integer.parseInt(request.getParameter("idcarrera"));
                ArrayList al = new ArrayList();
                JConexion jc = new JConexion("");
                Iterator it = null;
                if(consulta.equals("usuarios")){
                    query = "Select u.Nombre, u.Apellido_P, u.Apellido_M, u.Direccion, u.Ciudad, u.Telefono, u.UserName "
                            + "From cat_usuario u Where u.Activo = 1;";
                    al.clear();
                    al = jc.MySQLArray("MySQLRM", "Consulta", query);
                    it = al.iterator();
                    int pos = 0;
                    while(it.hasNext()){
                        dat = (String[]) al.get(pos);
                %>
                <br>
                <br>
                <table align="center">
                <tr>
                    <th align="left">Nombre: </th><td colspan="3"><% out.println(dat[0].toString() + " " + dat[1].toString() + " " + dat[2].toString()); %></td>
                </tr><tr>
                    <th align="left">Direccion: </th><td><% out.println(dat[3].toString()); %></td><th align="right">Telefono: </th><td><% out.println(dat[5].toString()); %></td>
                </tr><tr>
                    <th align="left">Ciudad: </th><td colspan="3"><% out.println(dat[4].toString()); %></td>
                </tr><tr>
                    <th align="left">Username: </th><td><% out.println(dat[6].toString()); %></td>
                </tr>
            </table>
                <hr>
                <%
                        it.next();
                        pos++;
                    }
                    }else if(consulta.equals("caballos")){
                        query = "Select c.Nombre, c.Momio, c.Jinete From cat_caballo c Where c.Activo = 1";
                        al.clear();
                        al = jc.MySQLArray("MySQLRM", "Consulta", query);
                        it = al.iterator();
                        int pos = 0;
                        while(it.hasNext()){
                            dat = (String[]) al.get(pos);
                %>
                <br>
                <br>
                <table align="center">
                <tr>
                    <th align="left">Nombre: </th><td colspan="3"><% out.println(dat[0].toString()); %></td>
                </tr><tr>
                    <th align="left">Jinete: </th><td><% out.println(dat[2].toString()); %></td><th align="right">Momio: </th><td><% out.println(dat[1].toString()); %></td>
                </tr>
            </table>
                <hr>
                <%
                        it.next();
                        pos++;
                        }
                    }else if(consulta.equals("carreras")){
                        query = "SELECT c.Descripcion, ca.Nombre, ca.Momio, ca.Jinete, r.posicion_salida, r.peso FROM rel_carrera_caballo r, cat_carrera c, cat_caballo ca WHERE r.fk_id_carrera = " + idcarrera + " and c.id_carrera = r.fk_id_carrera and ca.id_caballo = r.fk_id_caballo;";
                        al.clear();
                        al = jc.MySQLArray("MySQLRM", "Consulta", query);
                        it = al.iterator();
                        int pos = 0;
                        dat = (String[]) al.get(pos);
                %>
                <br>
                <br>
                <center>
                <table>
                    <tr>
                        <th colspan="5" align="left"><% out.println(dat[0].toString()); %></th>
                    </tr><tr>
                        <th align="center">Posicion</th><th align="center">Caballo</th><th align="center">Peso</th><th align="center">Jinete</th><th align="center">Momio</th>
                    </tr>
                    <% while(it.hasNext()){ %>
                    <tr>
                        <td align="center"><% out.println(dat[4].toString()); %></td><td align="center"><a href="apuesta_individual.jsp?nombre=<%= dat[1].toString()%>"><% out.println(dat[1].toString()); %></a></td><td align="center"><% out.println(dat[5].toString()); %></td><td align="center"><% out.println(dat[3].toString()); %></td><td align="center"><% out.println(dat[2].toString()); %></td>
                    </tr>
                    <%
                        pos++;
                        if(pos<=al.size()-1){
                        dat = (String[]) al.get(pos);
                        }
                        it.next();
                        }
                    %>
                </table>
                <a href="<% out.println("http://" + request.getLocalName()+ ":" + request.getLocalPort() + "/RoyalMowes/apuesta_individual.jsp?idcarrera=" + idcarrera+ "&user=" + user); %>">Apuesta en esta carrera</a>
                </center>
                    <hr>
                <%
                                                
                    }else if(consulta.equals("resultados")){}
                %>
            
        </form>
    </body>
</html>
